package ms.core.common;

import lombok.Data;
import ms.core.common.utils.CodeTableUtils;

@Data
public class AppException extends RuntimeException {
	private static final long serialVersionUID = -3836253551477434569L;

	private String code;
	private String msg;

	public AppException(Throwable throwable) {
        super(throwable);
		Throwable targetEx = throwable.getCause();
		if (targetEx==null) targetEx = throwable;
		if (targetEx instanceof AppException) {
			this.code = ((AppException) targetEx).getCode();
			this.msg = ((AppException) targetEx).getMsg();
		}
	}

	public AppException(String code) {
		super();
		this.code = code;
		this.msg = CodeTableUtils.codeOfMsg(code);
	}

	public AppException(String code, Throwable throwable) {
		super(throwable);
		this.code = code;
		this.msg = CodeTableUtils.codeOfMsg(code);
	}

	public AppException(String code, String msg) {
		super(msg);
		this.code = code;
		this.msg = msg;
	}

	public AppException(String code, String msg, Throwable throwable) {
		super(throwable);
		this.code = code;
		this.msg = msg;
	}
}
